/**
 * 项目业务请求接口
 */

 import request from './request'

 //封装登录接口
 export function LoginApi(data){ 
   return request({
     url: '/login',
     method: 'POST',   //delete ,put  
     data
   })
 }

 //左侧菜单接口  getMenusApi
 export function getMenusApi(){
    return request({
       url:'/menus',
       method:'GET'
    })
 }


 //用户列表接口
 export  function getUserListapi(params){
    return request({
       url:'/users',
       method:'GET',    //get
       params
    })
 }

 //添加用户的接口
 export function addUserApi(data){ 
    return request({
        url:'/users',
        method:'POST',
        data
    })
 }

/**
 * 
 * @param {number} userid 
 * @param {object} data {email mobile}
 * @returns 
 */
 //修改用户列表
 export function addUserApis(userid,data){ 
    return request({
        url:`users/${userid}`,
        method:'PUT',
        data
    }) 
 }

 //删除用户的方法
 export function delApi(id){ 
     return request({
         url:`users/${id}`, 
         method:'Delete',
     })
 }


//修改用户状态
export function getzhuangApi(userid,type){ 
    return request({
        url:`users/${userid}/state/${type}`,
        method:'PUT'
    })
}

//分配用户角色
export function getfenApl(id,rid){ 
    console.log(id,rid) 
     return request({
          url:`users/${id}/role`,
          method:'PUT',
          data:{rid} 
     })
}

 //角色列表
 export function getjueseApi(params){
     return request({
         url:'/roles',
         method:'GET',
         params
     })
 }

 //添加角色的接口
 export function addjueseApi(data){ 
     return request({
        url:'/roles',
        method:"POST",
        data
     }) 
 } 
 //删除角色
 export  function deljueseApi(id){
    return request({
         url:`roles/${id}`,
         method:'DELETE',
         
    })
} 

//编辑角色,
export  function bianjueseApi(id,{roleName,roleDesc}){ 
    console.log("id",id)
    return request({
         url:`roles/${id}`,
         method:'PUT',
         data:{roleName,roleDesc}
    })
}

//权限列表的接口
export function getquanxianApi(type){
    console.log(type)
    return request({
         url:`rights/${type}`,
         method:'GET',

    })
}


//角色列表
export function getrolelist(roleId,rids){
    return request({
         url:`roles/${roleId}/rights`,
         method:'POST',
         data:{rids}
    })
}


export function  shanjueseApi(roleId,rightId){
     return request({
          url:`roles/${roleId}/rights/${rightId}`,
          method:'delete',
     })
}

//商品列表数据
export function getgoodsApi(params){
     return request({
          url:'goods',
          method:"GET",
          params
     })
}

//商品分类
export function getGoodsCateApi(params){
     return request({
          url:'/categories',
          method:'GET',
        params
     })
}

//获取商品参数
export function getGoodsParamsApi(id,sel='many'){ 
     return request({ 
          url:`/categories/${id}/attributes`,
          method:"GET",
          params:{sel}
     }) 
}
